package seq_diverse.main;

import java.util.*;
import java.io.*;

public class FASTQParse extends BaseParse {
    private BufferedReader fin;

    public FASTQParse(final String filename) throws IOException {
	fin = new BufferedReader(new FileReader(filename));
    }

    public String getSequence(){
	String ans = "";

	boolean on_seq_header = true;
        boolean on_seq = false;
        boolean on_qual = false;

        int num_seq_lines = 0;
        int num_qual_lines = 0;

	String line;
	try {
	    while((line = fin.readLine()) != null){
		if(on_seq_header){
		    on_seq_header = false;
		    on_seq = true;
		    continue;
		}

		if(on_seq && line.charAt(0) == '+'){
		    on_seq = false;
		    on_qual = true;
		    continue;
		}

		if(on_qual){
		    num_qual_lines++;
		    if(num_seq_lines == num_qual_lines){
			return ans;
		    }
		    continue;
		}

		if(on_seq){
		    ans += line;
		    num_seq_lines++;
		    continue;
		}
	    }

	    return null;

	}catch(IOException ie){
	    ie.printStackTrace();
	    return null;
	}
    }

    /**
    private void parseHeader(){
	String line;
	long pos = 0;
	try {
	    pos = fin.getFilePointer();
	    while((line = fin.readLine()) != null){
                String tag = line.substring(0,1);
                if(tag.equals("#")){
		    pos = fin.getFilePointer();
                }else{
                    break;
                }
            }

            if(pos >=0){
                fin.seek(pos);
            }
        }catch(IOException ie){
	    ie.printStackTrace();
	}
    }
    **/
    
}